<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <%@include file="/WEB-INF/jsp/common.jsp"%>
</head>
<body>
    <div class="layui-fluid">
        <h2>收费管理</h2>
        <hr>
        <form action="" class="layui-form">
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-sm3"  style="margin-right: 0;">
                    <label class="layui-form-label">病历号：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="memberCaseNo"  placeholder="病历号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-col-sm3"  style="margin-right: 0;">
                    <label class="layui-form-label">患者姓名：</label>
                    <div class="layui-input-inline">
                        <input type="text" id="memberCaseName"  placeholder="患者姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-col-sm3" style="margin-right: 0;">
                    <label class="layui-form-label">支付状态：</label>
                    <div class="layui-input-inline">
                        <select name="pstate" id="pstate" lay-verify="pstate">
                            <option value="-1">请选择状态</option>
                            <option value="0">未支付</option>
                            <option value="1">已支付</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-col-sm3"  style="margin-right: 0;">
                    <button type="button" class="layui-btn layui-btn-sm" onclick="reloadData();"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                </div>
            </div>
        </form>
        <table id="patmentTable" lay-filter="patmentTable"></table>

        <script>
            var cardMemberId ;

            function zhifu(memberCaseNo) {
                //payId 财务列表id
                $.get("${path}/patment/get",{memberCaseNo:memberCaseNo},function (getstr) {

                    $.get("${path}/patment/jiezhang",function (formstr) {

                        layer.open({
                            type: 1,
                            title:"支付",
                            content: formstr,
                            area: ['100%','100%'],
                            btn:['确定','取消'],
                            maxmin: true,
                            success:function(){
                                getstr["memberId"] = getstr.caseInfo.memberId.cardMemberId;
                                getstr["userName"] = getstr.caseInfo.userId.username;
                                getstr["memberCaseNo"] = getstr.caseInfo.memberCaseNo.medicalRecordNo;
                                layui.form.val('zhifu',getstr);
                                //会员卡号
                                cardMemberId = getstr.memberId
                            },
                            yes:function (index) {
                                layui.layedit.sync(index)
                                console.log(index);
                                console.log(layui.layedit.getContent(1))
                                var moneyType = $("#moneyType").val();

                                if (moneyType == null){
                                    layer.msg('请选择支付方式', function(){});
                                    return
                                }
                                var params = $("#zhifu").serialize();

                                console.log(params)
                                if (moneyType == "现金"){
                                    $.get("${path}/patment/zhifu",params,function (data) {
                                        layui.table.reload("patmentTable")
                                        layer.close(index);
                                    })
                                }else if(moneyType == "会员卡"){
                                    var huiyuanyue = $(".huiyuankayue").text();
                                    var zongjine = $(".zongjine:eq(0)").text();
                                    console.log(huiyuanyue);
                                    console.log(zongjine);


                                    if(parseInt(zongjine)>parseInt(huiyuanyue)){
                                        layer.msg('好尴尬，会员卡没钱了');
                                        return
                                    }

                                    var chongzhi = parseInt(huiyuanyue) - parseInt(zongjine);
                                    var cardTranId = $("#memberId").val();
                                    console.log(cardTranId)
                                    $.post("${path}/cardtraninfo/shoufei",{cardTranId:cardTranId,chongzhi:chongzhi},function (money) {
                                        $.get("${path}/patment/zhifu",params,function (data) {
                                            layui.table.reload("patmentTable")
                                            layer.close(index);
                                        })
                                    })
                                }





                            }
                        });
                    })
                })
            }

            function chakan(memberCaseNo) {
                //payId 财务列表id
                $.get("${path}/patment/get",{memberCaseNo:memberCaseNo},function (getstr) {
                    cardMemberId = getstr.memberId.cardMemberId;
                    console.log(cardMemberId)


                    $.get("${path}/patment/xiangqing",function (formstr) {

                        layer.open({
                            type: 1,
                            title:"查看详情",
                            content: formstr,
                            area: ['100%','100%'],
                            btn:['确定','取消'],
                            maxmin: true,
                            success:function(){

                                getstr["memberId"] = getstr.caseInfo.memberId.cardMemberId;
                                getstr["userName"] = getstr.caseInfo.userId.username;
                                getstr["memberCaseNo"] = getstr.caseInfo.memberCaseNo.medicalRecordNo;
                                layui.form.val('zhifu',getstr);
                                //会员卡号
                                cardMemberId = getstr.memberId
                            },
                            yes:function (index) {
                                layer.close(index);
                            }
                        });
                    })
                })
            }

            function reloadData(){
                layui.table.reload("patmentTable",{
                    page:{
                        curr : 1
                    },
                    where : {
                        memberCaseNo : $("#memberCaseNo").val(),
                        memberCaseName : $("#memberCaseName").val(),
                        pstate:$("#pstate").val()
                    }
                })
            }
            layui.use(['form','table','layedit'], function(){
                var table= layui.table;
                var form = layui.form;

                //渲染表格
                table.render({
                    elem: '#patmentTable',
                    url: '${path}/patment/getlist',
                    page:true,
                    even: true,
                    toolbar:'#toolbarDemo',
                    cols:[[
                        {field:'payId',title:'编号'},
                        {field:'memberCaseName',title:'患者名称'},
                        {field:'memberCaseNo',title:'病例编号'},
                        {field:'payDateTime',title:'支付时间',templet:function (d) {
                                if (d.payDateTime == null){
                                    return "未支付"
                                }
                                return d.payDateTime
                            }},
                            {field:'pstate',title:'支付状态',templet: function(d){
                                if (d.pstate == 0){
                                    return "未支付"
                                } else{
                                    return "已支付"
                                }
                            }},
                            {field:'moneyType',title:'支付方式',templet: function(d){
                                if (d.moneyType == null){
                                    return "未支付"
                                } else{
                                    return d.moneyType
                                }
                            }},
                        {field:'hello', title:'操作',templet: function(d){
                                if (d.pstate == 0){
                                    return '<a href="javascript:void(0)" onclick="zhifu('+d.memberCaseNo+')">支付</a>'
                                } else{
                                    return '<a href="javascript:void(0)" onclick="chakan('+d.memberCaseNo+')">查看详情</a>'
                                }
                            }}
                    ]]
                })


            })
        </script>



    </div>
</body>
</html>
